
#ifndef __SOCK_INET_UDP_HPP__
#define __SOCK_INET_UDP_HPP__

////////////////////////////////////////////////////////////////////////////////

#include "sock-inet.hpp"

#include <stdint.h>

////////////////////////////////////////////////////////////////////////////////

class sock_inet_udp : public sock_inet
{
public:
    class packet
    {
    friend class sock_inet_udp;

    public:
        packet(uint8_t* buffer, size_t len);
        packet(const uint8_t* buffer, size_t len, const address& addr);
        packet(const packet&);
        const uint8_t* get_buffer() const;
        uint8_t* get_buffer();
        size_t get_len() const;
        const address& get_address() const;
        address& get_address();

    protected:
        packet();

        uint8_t* buffer;
        const uint8_t* const_buffer;
        size_t len;
        address addr;
    };

    template <int n = 0>
    class packet_n : public packet
    {
    friend class sock_inet_udp;

    public:
        packet_n()
            : packet(buffer_a, n)
        {
        }

    protected:
        uint8_t buffer_a[n];
    };

    sock_inet_udp();
    sock_inet_udp& operator>>(const timeout& t);
    sock_inet_udp& operator>>(packet& p);
    sock_inet_udp& operator<<(const packet& p);
    void recvfrom(packet& p);
    void sendto(const packet& p);

    static sock_inet_udp bind(const address& a);

protected:
    sock_inet_udp(const address& a);
};

////////////////////////////////////////////////////////////////////////////////

#endif
